/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Fenetre;

import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.swing.JComboBox;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;

/**
 *
 * @author Simon
 */
public class ComboBoxSessions extends JComboBox {

    public ComboBoxSessions() throws Exception {

        SAXBuilder sxb = new SAXBuilder();
        try {
            Document document = sxb.build(new File("fichiers/sessions.xml"));
            Element racine = document.getRootElement();

            List<Element> listeSites = racine.getChildren("site");
            for (Element site : listeSites) {
                List<Element> listeCursus = site.getChildren("cursus");
                for (Element cursus : listeCursus) {
                    List<Element> listePromotions = cursus.getChildren("promotion");
                    for (Element promotion : listePromotions) {
                        this.addItem(cursus.getAttributeValue("nom") + "-" + site.getAttributeValue("nom").substring(0, 1) + promotion.getText());
                    }
                }
            }
        } catch (JDOMException | IOException e) {
            throw new Exception(e.getMessage());
        }
    }
}
